home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 September / PCWorld_2008-09_cd.bin / domacnost a kancelar / joomla / Joomla_1.5.4-Stable-Full_Package.exe / plugins / system / remember.php < prev    next >
PHP Script  |  2008-07-06  |  2KB  |  78 lines

  1. <?php
  2. /**
  3. * @version        $Id: remember.php 10381 2008-06-01 03:35:53Z pasamio $
  4. * @package        Joomla
  5. * @copyright    Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
  6. * @license        GNU/GPL, see LICENSE.php
  7. * Joomla! is free software. This version may have been modified pursuant
  8. * to the GNU General Public License, and as distributed it includes or
  9. * is derivative of works licensed under the GNU General Public License or
  10. * other free or open source software licenses.
  11. * See COPYRIGHT.php for copyright notices and details.
  12. */
  13.  
  14. // no direct access
  15. defined( '_JEXEC' ) or die( 'Restricted access' );
  16.  
  17. jimport( 'joomla.plugin.plugin' );
  18.  
  19. /**
  20.  * Joomla! System Remember Me Plugin
  21.  *
  22.  * @author        Louis Landry <louis.landry@joomla.org>
  23.  * @package        Joomla
  24.  * @subpackage    System
  25.  */
  26. class plgSystemRemember extends JPlugin
  27. {
  28.     /**
  29.      * Constructor
  30.      *
  31.      * For php4 compatability we must not use the __constructor as a constructor for plugins
  32.      * because func_get_args ( void ) returns a copy of all passed arguments NOT references.
  33.      * This causes problems with cross-referencing necessary for the observer design pattern.
  34.      *
  35.      * @access    protected
  36.      * @param    object    $subject The object to observe
  37.      * @param     array   $config  An array that holds the plugin configuration
  38.      * @since    1.0
  39.      */
  40.     function plgSystemRemember(& $subject, $config) {
  41.         parent::__construct($subject, $config);
  42.     }
  43.  
  44.     function onAfterInitialise()
  45.     {
  46.         global $mainframe;
  47.  
  48.         // No remember me for admin
  49.         if ($mainframe->isAdmin()) {
  50.             return;
  51.         }
  52.  
  53.         $user = &JFactory::getUser();
  54.         if (!$user->get('gid'))
  55.         {
  56.             jimport('joomla.utilities.utility');
  57.             $hash = JUtility::getHash('JLOGIN_REMEMBER');
  58.  
  59.             if ($str = JRequest::getString($hash, '', 'cookie', JREQUEST_ALLOWRAW | JREQUEST_NOTRIM))
  60.             {
  61.                 jimport('joomla.utilities.simplecrypt');
  62.  
  63.                 //Create the encryption key, apply extra hardening using the user agent string
  64.                 $key = JUtility::getHash(@$_SERVER['HTTP_USER_AGENT']);
  65.  
  66.                 $crypt    = new JSimpleCrypt($key);
  67.                 $str    = $crypt->decrypt($str);
  68.  
  69.                 $options = array();
  70.                 $options['silent'] = true;
  71.                 if (!$mainframe->login(@unserialize($str), $options)) {
  72.                     // Clear the remember me cookie
  73.                     setcookie( JUtility::getHash('JLOGIN_REMEMBER'), false, time() - 86400, '/' );
  74.                 }
  75.             }
  76.         }
  77.     }
  78. }